package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao dao ;


    @Override
    public UserBean land(String userName, String password) {
        return dao.land(userName,password);
    }

    @Override
    public List<UserBean> findAll() {
        return dao.findAll();
    }

    @Override
    public boolean del(Integer id, UserBean loginUser) {

        if (loginUser.getId()==dao.findById(id).getId()){
            return false;
        }{
            dao.del(id);
            return true;
        }

    }

    @Override
    public UserBean findById(Integer id) {
        return dao.findById(id);
    }

    @Override
    public void updateGrade(Integer id, String grade) {
        dao.updateGrade(id,grade);
    }

    @Override
    public void updatePassword(Integer id, String password) {
        dao.updatePassword(id,password);
    }

    @Override
    public boolean add(UserBean user) {
        if (checkName(user.getUserName())){
            dao.add(user);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean checkName(String name) {
        return dao.checkName(name);
    }
}
